package tps.video_games;

import java.awt.Color;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.GameScene;
import com.uqbar.vainilla.appearances.Rectangle;
import com.uqbar.vainilla.events.constants.Key;
import com.uqbar.vainilla.events.constants.MouseButton;

public class Paleta extends GameComponent<GameScene>{
	private int width = 100;
	private int height = 15;
	private boolean modoLaser = false;
	
	public Paleta() {
		super(400,600);
		this.setAppearance(new Rectangle(Color.GRAY, this.width, this.height));
	}
	
	@Override
	public void update(DeltaState deltaState) {
		//MOVIMIENTO CON EL TECLADO
//		if(deltaState.isKeyPressed(Key.LEFT) && this.getX() > 0)
//			this.move(-20, 0);
//		if(deltaState.isKeyPressed(Key.RIGHT) && this.getX() < this.getGame().getDisplayWidth() - this.width)
//			this.move(20, 0);
		//MOVIMIENTO CON EL MOUSE
		double Xmouse = deltaState.getCurrentMousePosition().getX();
		if(Xmouse > 0 && Xmouse < this.getGame().getDisplayWidth() - this.getWidth())
			this.setX(Xmouse);
		
		if(this.modoLaser && deltaState.isMouseButtonPressed(MouseButton.LEFT))
			this.getGame().getCurrentScene().addComponent(new Bala(this));			

		super.update(deltaState);
	}
	
	public void ensanchar(){
		if(this.puedoEnsarcharmarme()){
			((Arkanoid)this.getGame()).sacarPoderes();
			this.width+=50;
			this.setAppearance(new Rectangle(Color.GRAY, this.width, this.height));
		}		
	}
	
	public boolean puedoEnsarcharmarme(){
		return this.width < 150;
	}
	
	public void achicar(){
		if(this.puedoAchicarme()){
			((Arkanoid)this.getGame()).sacarPoderes();
			this.width-=50;
			this.setAppearance(new Rectangle(Color.GRAY, this.width, this.height));
		}		
	}
	
	public boolean puedoAchicarme(){
		return this.width > 50;
	}	

	public void modoLaser() {
		((Arkanoid)this.getGame()).sacarPoderes();
		this.width = 100;
		this.modoLaser = true;
		this.setAppearance(new Rectangle(Color.MAGENTA, this.width, this.height));
		
	}
	
	//se llama al pasar de nivel,perder una vida u obtener algun poder
	public void reinicializar(){
		this.width = 100;
		this.modoLaser = false;
		this.setAppearance(new Rectangle(Color.GRAY, this.width, this.height));		
	}
	
	//ACCESORS
	
	public int getHeight() {
		return height;
	}

	public double getWidth() {
		return this.width;
	}
	

}
